<template>
  <div class="home">
    <el-card>
      <el-form ref="form" :model="user" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="user.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="user.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login()">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //属性 定义变量
      user: {}
    }
  },
  methods: {//定义方法
    login() {
      //http://localhost:8080/login?username=zhangsan&password=21312
      this.axios.post("http://localhost:19000/v1/user/login", this.qs.stringify(this.user))
          .then((response) => {
            if (response.data.code == 20000) {
              localStorage.setItem("user", JSON.stringify(response.data.data))
              this.$message.success("登录成功")

              setTimeout(()=>{
                window.location.reload() //刷新页面
              },2000)

              this.$router.push("/")//页面跳转 / 路由跳转

            } else {
              this.$message.error(response.data.message)
            }
          })
    }
  },
  mounted() {//在网页刷新或被加载的时候执行

  }
}
</script>

<style>

</style>
